package com.enjoyor.soa.traffic.server.tsms.dubbo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tsms.TemplateDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboTemplateService;
import com.enjoyor.soa.traffic.core.tsms.domain.Template;
import com.enjoyor.soa.traffic.core.tsms.service.ITemplateExampleService;
import com.enjoyor.soa.traffic.frame.support.util.DomainUtil;
import com.enjoyor.soa.traffic.server.tsms.dubbo.invoke.DubboTokenServiceInvoke;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboTemplateService implements IDubboTemplateService {

    @Autowired
    private ITemplateExampleService templateExampleService;

    @Autowired
    private DubboTokenServiceInvoke dubboTokenServiceInvoke;

    public ResultPojo select(String id) {
    	Template template = templateExampleService.select(id);
        return new ResultPojo(ReflectHelper.beanToBean(template, TemplateDto.class));
    }

    @Override
	public ResultPojo selectList(String id, String type, String content){
		List<Template> templateList = templateExampleService.selectList(id, type, content);
		return new ResultPojo(ReflectHelper.listToList(templateList, TemplateDto.class));
	}
    
    @Override
    public ResultPojo selectPage(Page page, String timeStart, String timeEnd) {
        return new ResultPojo(templateExampleService.selectPage(page, timeStart, timeEnd));
    }
    
    public ResultPojo insert(TemplateDto templateDto, String userName) {
        templateExampleService.insert(ReflectHelper.beanToBean(templateDto, Template.class), userName);
        return new ResultPojo();
    }

    public ResultPojo edit(TemplateDto templateDto, String userName) {
        templateExampleService.edit(ReflectHelper.beanToBean(templateDto, Template.class), userName);
        return new ResultPojo();
    }

    public ResultPojo delete(String id, String userName) {
        templateExampleService.delete(id, userName);
        return new ResultPojo();
    }
    
    @Override
    public ResultPojo check(String token, String sysKey) {
        return dubboTokenServiceInvoke.check(token, sysKey);
    }

}
